/**
 * Flywheel Analog Sensor
 * 
 * That crazy looking thing that will measure the rotational speed of the 
 * flywheel, this sensor will operate based upon Hertz.
 */
package edu.wpi.first.wpilibj.templates.assets;

import edu.wpi.first.wpilibj.AnalogChannel;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.Timer;

/**
 *
 * @author Jarrod Risley
 */
public class FlywheelAnalogSensor {
    
    /*
     * Global Class Variables
     */
    private DigitalInput lightInputChannel;
    
    
    // CONSTRUCTOR //
    
    
    /**
     * Creates a FlywheelAnalogSensor that reads from the specified analog port.
     * 
     * @param channel An analog channel.
     */
    public FlywheelAnalogSensor(int lightChannel) {
        
        lightInputChannel = new DigitalInput(lightChannel);
        
    } // end FlywheelAnalogSensor Constructor
    
    
    // METHOD //
   
    /**
     * Gets the frequency of the flywheel (aka the period).
     * @param timeOne The initial startup time of the flywheel.
     * @return The frequency.
     */
    public double getFrequency() {
        
        double startTime = Timer.getFPGATimestamp();
        double timeOne = 0;
        
//        System.out.println("Start time is: " + startTime);
        
            if (!lightInputChannel.get() == true) {
                
//                timeOne = Timer.getFPGATimestamp();
                
                System.out.println("I have seen the light!");
                
            }  else
                System.out.println("Nothing seen by me.");
            
//        System.out.println("Measured Time is: " + timeOne);
//            
//        System.out.println("Frequency is: " + (1 / (timeOne - startTime)));
            
        return 1 / (timeOne - startTime);
        
    } // end getFrequency
    
    public boolean getInput() {
        return lightInputChannel.get();
    } // end getInput
    
} // end FlywheelAnalogSensor
